/*
 * sys_event.c
 *
 * realize system event function.
 *
 * Copyright (C) 2024 Sinh Micro, Inc.
 * Subject to the GNU Public License, version 2.
 *
 * Author: lixiang<lixiang@sinhmicro.com>
 * 
 * Encoding format: GB2312
 * Version: v1.2.2
 * Date: 2024-11-05
 */

#include "hal/inc/hal-regs.h"
#include "hal/inc/types.h"
#include "hal/inc/charger.h"
#include "hal/inc/power.h"
#include "hal/inc/adc.h"

#include "sys_event.h"
#include "ec_app_config.h"
#include "heat.h"
#include "battery.h"
#include "lvd.h"
#include "debug.h"
#include "power_manage.h"
#include "mic_det_api.h"
#include "ec_control.h"
#include "ui_event.h"

uint16_t event_state_mask;

bool sys_event_test_and_clr_mask(uint16_t event_mask)
{
    bool ret = event_state_mask & event_mask;
    event_state_mask &= ~event_mask;
    return ret;
}

void sys_event_handle_100ms(void)
{
    if (heat_event_oc) {
        heat_event_oc = false;
        event_state_mask |= EVENT_STATE_HEAT_OC;
    }

#if ((CONFIG_RES_MEASURE == 1) && (CONFIG_RES_MEASURE_TIME == 1) && (CONFIG_ENABLE_RES_MAX == 1))
    if (heat_event_op) {
        heat_event_op = false;
        event_state_mask |= EVENT_STATE_HEAT_OPEN_CIRCULT;
    }
#endif
}
